package com.colin.controller;

import com.alibaba.fastjson.JSONObject;
import com.colin.dubbo.business.request.Demo1Request;
import com.colin.dubbo.business.response.CommonResponse;
import com.colin.dubbo.enums.MethodEnum;
import com.colin.dubbo.service.BaseService;
import com.colin.log.util.LogUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;

@RestController
public class TestController {

    @Resource
    private BaseService baseService;

    @RequestMapping(value = "/test", produces="application/json;charset=UTF-8")
    public Object test(TestRequest param){

        Demo1Request request = new Demo1Request();
        request.setMethod(MethodEnum.DEMO1);
        request.setDemo1(JSONObject.toJSONString(param));

        LogUtil.info("demo1 request:" + JSONObject.toJSONString(request));
        CommonResponse handle = baseService.handle(request);
        LogUtil.info("demo1 response:" + JSONObject.toJSONString(handle));

        return JSONObject.toJSONString(handle);
    }

    public static class TestRequest implements Serializable {
        private String param1;
        private String param2;

        public String getParam1() {
            return param1;
        }

        public void setParam1(String param1) {
            this.param1 = param1;
        }

        public String getParam2() {
            return param2;
        }

        public void setParam2(String param2) {
            this.param2 = param2;
        }
    }

}
